{include file="public/head"/}
<style type="text/css">
.layui-table td, .layui-table th{
    position: relative;
    padding: 13px 10px;
    min-height: 19px;
    line-height: 19px;
    font-size: 14px;
}
</style>
<style type="text/css">
.layadmin-carousel{
	height: 100px !important;
    background-color: #fff;
}
.layadmin-backlog-body p cite {
    font-style: normal;
	color:#009688;
    font-size: 16px;
    font-weight:bold;
}
</style>
<div class="layui-content-wrapper">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space8">
        
            <!--数据统计开始-->
              <div class="layui-col-md12"> 
                    <div class="layui-card"> 
                       <div class="layui-card-header">数据统计</div> 
                       <div class="layui-card-body"> 
                        <div class="layui-carousel layadmin-carousel layadmin-backlog"> 
                         <div carousel-item=""> 
                          <ul class="layui-row layui-col-space10"> 
                           <li class="layui-col-xs4"><a href="javascript:;" class="layadmin-backlog-body"> <h3>应收总额</h3><p><cite>&yen; 1112554.00 </cite> 元</p> </a> </li> 
                           <li class="layui-col-xs4"> <a href="javascript:;" class="layadmin-backlog-body"> <h3>续费总额</h3> <p><cite>&yen; 0 </cite> 元</p> </a> </li> 
                          </ul> 
                         </div> 
                        </div> 
                       </div> 
                      </div>                         
              </div>     
            <!--数据统计结束-->
        
            <!--搜索开始-->
              <div class="layui-col-md12"> 
               <div class="layui-card"> 
                <div class="layui-card-header">搜索</div> 
                <div class="layui-card-body"> 
                 <div class="table-head-btn" style="margin-bottom: 10px;"> 
                  <div class="layui-form"> 
                   <div class="layui-inline"> 
                    <label class="layui-form-label" style="width:auto;">资讯分类</label> 
                    <div class="layui-input-inline"> 
                     <select name="label" lay-filter="label" lay-verify="required">
                        <option value="">请选择分类</option>
                        {volist name="categorys" id="vo"}
                        <option value="{$vo.id}">{$vo.lefthtml}{$vo.title}</option> 
                        {/volist} </select> 
                    </div> 
                   </div> 
                   <div class="layui-inline"> 
                    <label class="layui-form-label" style="width:auto;">关&nbsp; 键&nbsp; 词</label> 
                    <div class="layui-input-inline"><input class="layui-input" name="key" id="key" placeholder="请输入关键字" autocomplete="off" /></div> 
                   </div> 
                   <button class="layui-btn" data-type="reload">搜索</button> 
                  </div> 
                 </div> 
                </div> 
               </div> 
              </div>    
            <!--搜索结束-->
            
            <div class="layui-col-md12">
                <div class="layui-card"> 
                   <div class="layui-card-header">数据列表</div> 
                   <div class="layui-card-body"> 
                    <div class="clt-auth-btns" style="margin-bottom: 10px;"> 
                     <button class="layui-btn layuiadmin-btn-list layui-btn-sm" data-type="add"><i class="layui-icon layui-icon-add-1"></i>添加资讯</button> 
                     <button class="layui-btn layuiadmin-btn-list layui-btn-danger layui-btn-sm" data-type="deleteAll"><i class="layui-icon layui-icon-delete"></i>批量删除</button> 
                    </div> 
                    <table class="layui-hide" id="list" lay-filter="list"></table> 
                   </div> 
                  </div>
            </div>
        </div>
    </div>
</div>
{include file="public/foot"/}

<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="正常|禁用" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="recommend">
    <input type="checkbox" name="recommend" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="recommend" {{ d.recommend == 1 ? 'checked' : '' }}>
</script>

<script type="text/html" id="title">
    {{d.title}}
    {{# if(d.thumb){ }}<img src="/static/admin/images/image.gif" style="cursor:pointer;" onmouseover="layer.tips('<img src={{d.thumb}}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();">{{# } }}
</script>

<script type="text/html" id="category">
    <a  lay-event="category" href="javascript:void(0);">{{d.category_name}}</a>
</script>


<script type="text/html" id="action">
    <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<script>
    layui.config({
        base: '__LAYDMIN__',{if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table','carousel','form'],function(){
			var $ = layui.$;
			var admin = layui.admin;
			var table = layui.table;
			var element = layui.element;
			var form = layui.form;
			var util = layui.util;
			var upload = layui.upload;
			var carousel = layui.carousel;
			var device = layui.device();
		    var tableLoadDiv = window.top.layer.load(0,{shade:[0.5, '#000']}); //加载层,table.render完成时需要关闭
			//全部数据
			tableIn = table.render({
				elem: '#list',
				url: '{:url(SYS_PATH."/".CONTROLLER."/index")}',
				method: 'post',
				autoSort: false,
				loading:true,
				cols: [[
					{type: 'checkbox'},
					{field: 'id', title: 'ID', width: 50,align:'center'},
					{field: 'category_name', title: '分类名称', width: 120,align:'center',templet: '#category'},
					{field: 'title', title: '标题', width: 300,templet: '#title'},
					{field: 'description', title: '描述', width: 400},
					{field: 'hits', title: '阅读', width: 80,align:'center',sort:true},
					{field: 'recommend', align: 'center', title: '推荐', width: 120, toolbar: '#recommend'},
					{field: 'status', align: 'center', title: '状态', width: 120, toolbar: '#status',sort:true},
					{field: 'create_time', title: '创建时间', width: 200,sort:true,align:'center',
						templet: function(d){
							return util.toDateString(d.create_time*1000,'yyyy-MM-dd HH:mm:ss');
						}
					},
					{width: 160,title:'操作', align: 'center', toolbar: '#action'}
				]],
				page: true,
				done:function (res) {
			    	window.top.layer.close(tableLoadDiv);
			    }				
			});	
			
			table.on('sort(list)', function(obj){ 
			  table.reload('list', {
				initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
				,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
				  sort_by: obj.field //排序字段
				  ,sort_order: obj.type //排序方式
				}
			  });
			});			
			
			
		//列表编缉与删除---监听工具条
		table.on('tool(list)', function (obj) {
					var data = obj.data;
					var id = data.id;
					if (obj.event === 'del') {
						var uri="{:url(SYS_PATH.'/'.CONTROLLER.'/doDelete')}"
						layui.doDelete(uri,"确定要删除该条信息吗？",id,obj);//单个删除接口
					}else if (obj.event === 'edit') {
						layui.layerOpen("{:url(SYS_PATH.'/'.CONTROLLER.'/edit')}?id="+id);
					}else if (obj.event === 'category') {
							//执行重载
						table.reload('list', {
							page: {curr: 1 }, 
							where: {
								catid: data.catid
							}
						});
					}
		});			
			
			
		//改变状态
		form.on('switch(status)', function (obj) {
			var id = this.value;
			var status = obj.elem.checked === true ? 1 : 0;
			admin.req({
				url: '{:url(SYS_PATH.'/'.CONTROLLER.'/doStatus')}'
				, type: 'post'
				, data: {'id': id, 'status': status}
				, success: function (res) {
					if (res.code==0) {
						window.top.layer.msg(res.msg, {time: 1000, icon: 1,shade:[0.5,'#000']});
					} else {
						window.top.layer.msg(res.msg, {time: 1000, icon: 2,shade:[0.5,'#000']});
						if (obj.elem.checked == true) {
							$(obj.elem).prop('checked', false);
						} else {
							$(obj.elem).prop('checked', true);
						}
						form.render();
					}
				}
			});
		});
		
		//是否推荐状态
		form.on('switch(recommend)', function (obj) {
			var id = this.value;
			var recommend = obj.elem.checked === true ? 1 : 0;
			admin.req({
				url: '{:url(SYS_PATH.'/'.CONTROLLER.'/doRecommend')}'
				, type: 'post'
				, data: {'id': id, 'recommend': recommend}
				, success: function (res) {
					if (res.code==0) {
						window.top.layer.msg(res.msg, {time: 1000, icon: 1,shade:[0.5,'#000']});
					} else {
						window.top.layer.msg(res.msg, {time: 1000, icon: 2,shade:[0.5,'#000']});
						if (obj.elem.checked == true) {
							$(obj.elem).prop('checked', false);
						} else {
							$(obj.elem).prop('checked', true);
						}
						form.render();
					}
				}
			});
		});	
		
		//监听头部按钮
		$('.clt-auth-btns .layui-btn').on('click', function () {
			var type = $(this).data('type');
			if (type === 'add') {
				layui.layerOpen("{:url(SYS_PATH.'/'.CONTROLLER.'/add')}");
			}else if(type=='deleteAll'){
				layui.deleteAll("{:url(SYS_PATH.'/'.CONTROLLER.'/doDeleteAll')}","确定要批量删除吗？",tableIn);//tableIn为渲染列表对象
			}
		});			
			
		
		
		//搜索重载
		$('.table-head-btn .layui-btn').on('click', function () {
			var type = $(this).data('type');
			if (type === 'reload') {
				var key = $('#key').val();
				//执行重载
				table.reload('list', {
					page: {curr: 1 }, 
					where: {
						key: key
					}
				});
			}		
		});	
		
		//分类选择
		form.on('select(label)', function(data){
			var catid=data.value;
							//执行重载
			table.reload('list', {
					page: {curr: 1 }, 
					where: {
							catid: catid
						}
			});
		
		})		
		
        //轮播切换
        $('.layadmin-carousel').each(function () {
            var othis = $(this);
            carousel.render({
                elem: this
                , width: '100%'
                , arrow: 'none'
                , interval: othis.data('interval')
                , autoplay: othis.data('autoplay') === true
                , trigger: (device.ios || device.android) ? 'click' : 'hover'
                , anim: othis.data('anim')
            });
        });						

	});
</script>
</body>
</html>

